Online-Academy
Look, Read, Understand, Apply

Operating System

FAQs - I

  1. Define Process.

    Answer: A process is a program that is currently in execution. It consists of the program code, data, CPU registers, program counter, stack, and other resources required for execution.

  2. Why is Worst Fit better than Best Fit? Answer:
    • Best Fit allocates the smallest available memory block that is large enough for a process.
    • Worst Fit allocates the largest available memory block.
    • Worst Fit can sometimes be better because it leaves relatively large remaining holes after allocation, which may be useful for allocating larger processes later. Best Fit tends to create many very small unusable fragments.
    • However, Worst Fit is not always better; its effectiveness depends on the workload.
  3. What might be the contents of a PCB?

    Answer: A Process Control Block (PCB) contains information required by the operating system to manage a process, such as:

    • Process ID (PID)
    • Process state
    • Program counter
    • CPU registers
    • CPU scheduling information
    • Memory-management information
    • Accounting information
    • I/O status information
    • List of open files

  4. Define Process Scheduling Mechanism of an OS.

    Answer: Process scheduling is the mechanism used by an operating system to select a process from the ready queue and allocate the CPU to it. The scheduler determines which process should run next according to a scheduling algorithm such as FCFS, SJF, Priority, or Round Robin.

  5. What is a Semaphore?

    Answer: A semaphore is a synchronization variable used to control access to shared resources by multiple processes or threads. It is normally accessed through two atomic operations:

  6. wait() / P() — decreases the semaphore value.
  7. signal() / V() — increases the semaphore value.
  8. Semaphores can be binary or counting semaphores.
  9. What is Paging?

    Answer: Paging is a memory-management technique in which a process's logical memory is divided into fixed-size pages, while physical memory is divided into fixed-size frames. A page can be loaded into any available frame, allowing non-contiguous allocation of memory.

  10. What is a Bit Vector?

    Answer: A bit vector is a sequence of bits used to represent the allocation status of resources, particularly free and allocated disk blocks. For example:
    1 0 0 1 1 0
    If 1 represents an allocated block and 0 represents a free block, blocks 2, 3, and 6 are free.

  11. What is Decryption?

    Answer: Decryption is the process of converting encrypted or ciphertext data back into its original readable form, called plaintext, using a decryption key.

  12. What is I/O Optimization?

    Answer: I/O optimization refers to techniques used to improve the efficiency and performance of input/output operations. Examples include:

  13. Buffering
  14. Caching
  15. Spooling
  16. DMA
  17. I/O scheduling
  18. Reducing unnecessary I/O operations
  19. What are the Advantages of IPC?

    Answer: Inter-Process Communication (IPC) allows processes to exchange data and synchronize their activities. Advantages include:

  20. Data sharing
  21. Faster communication
  22. Process synchronization
  23. Resource sharing
  24. Modularity
  25. Improved system performance
  26. Common IPC mechanisms include shared memory, pipes, message queues, and sockets.
  27. How is a Process Created?

    Answer: A process can be created by an existing process using an operating-system system call. The general process is:

    1. An existing process, called the parent process, requests creation of a new process.
    2. The OS allocates a new PCB.
    3. A unique process ID is assigned.
    4. Memory and other required resources are allocated.
    5. The operating system initializes the process information.
    6. The new process, called the child process, is placed in the appropriate queue.
    7. The scheduler eventually allocates CPU time to the child process.
    8. In UNIX/Linux systems, the fork() system call is commonly used to create a child process.

    Uses of FORK and JOIN System Calls:
    fork() creates a new child process from an existing parent process. The child process initially receives a copy of the parent's execution context.
    Use: Creating a new process.

    JOIN: join() is used in process synchronization. It allows a parent process to wait for the completion of a child process or related process. Use: Synchronizing parent and child processes.

  28. Differentiate between Process and Thread. Answer:
    ProcessThread
    A program in executionA unit of execution within a process
    Has its own address spaceShares address space with other threads of the process
    Creation is relatively expensiveCreation is relatively inexpensive
    Context Switching is comparatively expensiveContext switching is generally faster
    Processes communicate using IPSThreads can communicate through shared memory
    More isolatedLess isolated
  29. What are the criteria for CPU scheduling? Answer:
    • CPU utilization - maximize CPU usage
    • Throughput - maximize completed processes per unit time
    • Turnaround time - minimize total time taken by a process
    • Waiting time - minimize time spent in the ready queue
    • Response time - minimize time unitl the first response
  30. Write the Role of Process Scheduling.

    Answer: Process scheduling determines which ready process receives the CPU and when. Its major roles are:

    1. Keeping the CPU efficiently utilized.
    2. Providing fair CPU allocation
    3. Improving system throughput
    4. Reducing waiting and turnaround time
    5. Providing good resonse time
    6. Supporting multitasking

  31. Differentiate between Voluntary vs Involuntary CPU Sharing. Answer:
    Voluntary CPU SharingInvoluntary CPU sharing
    A process gives up the CPU voluntarilyOS forcibly takes the CPU from a process
    Occurs when a process blocks or terminatesOccurs through preemption
    Common in non-preemptive schedulingCommon in preemptive scheduling
    Example: process waits for I/OExample: timer interrupt causes context switch
  32. What is Context Switching?

    Context switching is the process of saving the CPU state of the currently running process and loading the saved state of another process. The saved information may include:

    • Program counter
    • CPU registers
    • Stack pointer
    • Process state
    The OS uses the PCB to save and restore this information.

  33. Explain Three Pre-emptive Scheduling Algorithms.
    Round Robin: 
    Each process receives a fixed time interval called a time quantum.
    Example:
    
    Processes: P1, P2, P3
    Time quantum = 2 ms
    
    P1 -> P2 -> P3 -> P1 -> P2 -> ...
    
    When a process's quantum expires, it is preempted.
    Shortest Remaining Time First (SRTF)
    
    SRTF is the preemptive version of Shortest Job First.
    The process having the shortest remaining CPU burst time is selected.
    If a newly arrived process has a shorter remaining time than the currently running process, the current process is preempted.
    Preemptive Priority Scheduling
    
    Each process is assigned a priority.
    The process with the highest priority gets the CPU. If a higher-priority process arrives, the currently running process may be preempted. Example:
    
    ProcessPriority
    P13
    P21
    P32
    If smaller numbers represent higher priority, P2 gets the CPU first.
  34. What is Mutual Exclusion?

    Mutual exclusion is a synchronization mechanism that ensures that only one process or thread at a time can enter a critical section accessing a shared resource. For example, if two processes modify the same bank account simultaneously, mutual exclusion prevents inconsistent results.

  35. Define Race Condition and Explain Peterson's Solution.

    A race condition occurs when multiple processes or threads access shared data concurrently and the final result depends on the order in which their operations execute.

    Peterson's Solution
    
    Peterson's algorithm is a software-based solution for achieving mutual exclusion between two processes.
    
    It uses two variables:
    
    flag[2] — indicates whether a process wants to enter the critical section.
    turn — indicates which process should get priority.
    
    Conceptually:
    
    flag[i] = true;
    turn = j;
    
    while (flag[j] && turn == j)
        wait;
    
    Critical Section
    
    flag[i] = false;
    
    Remainder Section
    
    Peterson's solution provides:
    
    
  36. Mutual exclusion
  37. Progress
  38. Bounded waiting
  39. It is mainly important as a theoretical example; modern systems generally use hardware-supported synchronization primitives.